package com.king.login.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.king.login.dao.SystemUserMapper;
import com.king.login.entity.SystemUser;
import com.king.login.param.SystemUserParam;
import com.king.login.service.SystemUserService;
import com.king.platform.dto.PageDTO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * <p>todo SystemUser 服务接口实现</p>
 * @author: cuizx
 * @created: 2024-05-10 11:48:48
 * @version v1.0.1
 * @copyright: Copyright (c)  cuizx
 */
@Service("systemUserService")
public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemUser> implements SystemUserService {


    @Resource
    private SystemUserMapper systemUserMapper;
    
    /**
     * <p>todo 批量删除</p>
     * @param: ids
     * @return: SystemUser
     * @author: cuizx
     * @date: 2024-05-10 11:48:48
     * @version: 1.0.1
     * Modification History:
     * Date         Author          Version            Description
     * -----------------------------------------------------------
     * 2024-05-10 11:48:48    cuizx        v1.0.1             init
     */
     
    @Override
    public void deleteByIds(String ids) {
        String[] idsArr = ids.split(",");
        if (idsArr.length > 0) {
            List<Long> idList = Stream.of(idsArr).map(Long::valueOf).collect(Collectors.toList());
            systemUserMapper.deleteBatchIds(idList);
        }
    }
    
    
   /**
     * <p>todo 查询所有</p>
     * @param: model
     * @return: SystemUser
     * @author: cuizx
     * @date: 2024-05-10 11:48:48
     * @version: 1.0.1
     * Modification History:
     * Date         Author          Version            Description
     * -----------------------------------------------------------
     * 2024-05-10 11:48:48    cuizx        v1.0.1             init
     */
     
    @Override     
    public List<SystemUser> list(SystemUserParam model){
          
             //条件查询
        QueryWrapper<SystemUser> queryWrapper = new QueryWrapper<>();

        //动态sql
       //if(StringUtils.isNotBlank(model.getAuthor())){
           // queryWrapper.lambda().eq(SystemUser::getAuthor,model.getAuthor());
       // }

        //排序
        queryWrapper.lambda().orderByDesc(SystemUser::getId);

        //执行查询
        List<SystemUser> tempList = systemUserMapper.selectList(queryWrapper);

        //封装查询结果
        return tempList;
    }

     /**
     * <p>todo 分页查询</p>
     * @param: model
     * @return: SystemUser
     * @author: cuizx
     * @date: 2024-05-10 11:48:48
     * @version: 1.0.1
     * Modification History:
     * Date         Author          Version            Description
     * -----------------------------------------------------------
     * 2024-05-10 11:48:48    cuizx        v1.0.1             init
     */
     
    @Override
    public PageDTO<SystemUser> listPage(SystemUserParam model){

        //没有传分页参数时，默认设置查询前10条数据
        Page<SystemUser> page = Page.of(model.getCurrentPage(),model.getPageSize());
        //条件查询
        QueryWrapper<SystemUser> queryWrapper = new QueryWrapper<>();

        //动态sql
        //if (StringUtils.isNotBlank(model.getAuthor())) {
        //    queryWrapper.lambda().eq(Member::getAuthor, model.getAuthor());
        // }
        //排序
        queryWrapper.lambda().orderByDesc(SystemUser::getId);

        //执行查询
        Page<SystemUser> result = systemUserMapper.selectPage(page, queryWrapper);
        PageDTO<SystemUser> pageInfo = new PageDTO<>();
        pageInfo.setList(result.getRecords());
        pageInfo.setPages(page.getPages());
        pageInfo.setTotal(page.getTotal());
        //封装查询结果
        return pageInfo;
    }
}


